package com.antu.first.util;

import java.util.List;

public class PageBean {

	private Integer currentPage;// 当前页数（页面要跳转的页数，用户输入）
	private Integer totalCount;// 总记录数（数据库查出来的不用传入）
	private Integer pageSize;// 每页显示条数（页面传入，用户通过下拉框的方式选择）
	private Integer totalPage;// 总页数（通过传入的每页显示条数，和数据库查出来的数据，进行计算出来的）
	private List list;// 分页列表数据
	private Integer start;// 起始索引
	public PageBean(Integer currentPage, Integer totalCount, Integer pageSize) {
		this.totalCount = totalCount;
		this.currentPage = currentPage;
		this.pageSize = pageSize;
		if (this.currentPage == null) {
			// 如果页面没有指定显示哪一页，那么显示第一页
			this.currentPage = 1;
		}
		if (this.pageSize == null) {
			// 如果每页显示条数没有指定，默认显示3条
			this.pageSize = 10;
		}
		// 计算总页数
		this.totalPage = (this.totalCount + this.pageSize - 1) / this.pageSize;
		// 判断当前页数是否超出范围
		// 不能小于1
		if (this.currentPage < 1) {
			this.currentPage = 1;
		}
		// 不能大于总页数
		if (this.currentPage > this.totalPage) {
			this.currentPage = this.totalPage;
		}
		this.start = (this.currentPage - 1) * this.pageSize;
		if (this.start<0){
			this.start=0;
		}
	}

	// 计算起始索引
	public int getStart() {
		return this.start;
	}

//	public int setStart(Integer start) {
//		return (this.currentPage - 1) * this.pageSize;
//	}
	public Integer getCurrentPage() {
		return currentPage;
	}
	public void setCurrentPage(Integer currentPage) {
		this.currentPage = currentPage;
	}

	public Integer getTotalCount() {
		return totalCount;
	}

	public void setTotalCount(Integer totalCount) {
		this.totalCount = totalCount;
	}

	public Integer getPageSize() {
		return pageSize;
	}

	public void setPageSize(Integer pageSize) {
		this.pageSize = pageSize;
	}

	public Integer getTotalPage() {
		return totalPage;
	}

	public void setTotalPage(Integer totalPage) {
		this.totalPage = totalPage;
	}

	public List getList() {
		return list;
	}

	public void setList(List list) {
		this.list = list;
	}

	@Override
	public String toString() {
		return "PageBean{" +
				"currentPage=" + currentPage +
				", totalCount=" + totalCount +
				", pageSize=" + pageSize +
				", totalPage=" + totalPage +
				", list=" + list +
				", start=" + start +
				'}';
	}
}
